﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Drawing;
using System.Windows.Forms;
namespace ButtonTree2
{
    public class MenuItemRanderer: ToolStripProfessionalRenderer
    {
        public MenuItemRanderer()
        {

        }

        private static MenuItemRanderer _rendererInstance = null;

        public static MenuItemRanderer Instance
        {
            get
            {
                if (_rendererInstance == null)
                {
                    _rendererInstance = new MenuItemRanderer();
                }
                return _rendererInstance;
            }
        }

        // MenuItem背景
        protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
        {
            if (e.Item.Enabled)
            {
                RibbonPaintUtils.PaintRibbonMenuItemBackground(e.Graphics, e.Item.ContentRectangle, e.Item.Selected);
            }
        }

        
        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
        {
            //RibbonPaintUtils.PaintRibbonToolStripBackground(e.Graphics, e.AffectedBounds);
            e.Graphics.FillRectangle(Brushes.White, e.AffectedBounds);
        }

//         protected override void OnRenderItemImage(ToolStripItemImageRenderEventArgs e)
//         {
//             using (Brush brush = new SolidBrush(RibbonConfigUtils.TabBackLinearColor_1))
//             {
//                 e.Graphics.FillRectangle(brush, e.Item.ContentRectangle);
//             }
//         }
// 
//         protected override void OnRenderOverflowButtonBackground(ToolStripItemRenderEventArgs e)
//         {
//             using (Brush brush = new SolidBrush(RibbonConfigUtils.TabBackLinearColor_1))
//             {
//                 e.Graphics.FillRectangle(brush, e.Item.ContentRectangle);
//             }
//         }

//         protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
//         {
//             
//         }

        protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
        {
            using (Pen pen = new Pen(RibbonConfigUtils.MenuBoundColor))
            {
                Rectangle rect = new Rectangle(
                    new Point(e.AffectedBounds.Left, e.AffectedBounds.Top),
                    new Size(e.AffectedBounds.Width - 1, e.AffectedBounds.Height - 1)
                    );
                //GraphicsUtils.DrawRoundRect(e.Graphics, pen, null, rect, 3f);
                e.Graphics.DrawRectangle(pen, rect);
            }
        }

        protected override void OnRenderImageMargin(ToolStripRenderEventArgs e)
        {
            using (Brush brush = new SolidBrush(RibbonConfigUtils.TabBackLinearColor_2))
            {
                e.Graphics.FillRectangle(brush, e.AffectedBounds);
            }
        }
    }
}
